package main.java.indi.zyj.c150.greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class _08_ReconstructQueue {


    public static int[][] reconstructQueue(int[][] people) {

        Arrays.sort(people, (int[] people1, int[] people2) ->
                people2[0] != people1[0] ? people2[0] - people1[0] : people1[1] - people2[1]);

        List<int []> newQueue = new ArrayList<>();

        for (int[] person : people) {
            newQueue.add(person[1], person);
        }

        return newQueue.toArray(new int[newQueue.size()][]);

    }

    public static void main(String[] args) {
        int[][] people = {{7, 0}, {4, 4}, {7, 1}, {5, 0}, {6, 1}, {5, 2}};
        reconstructQueue(people);
    }
}
